﻿using System;
using System.Collections.Generic;
using System.Text;
using QLKCB.Model;
using QLKCB.Common;

namespace QLKCB.Controller
{
    class cPhieuThu
    {

        Utils utils = new Utils();
        ConnectDB connectDB = new ConnectDB();

        public string getMaPhieuThu()
        {
            string prefixKey = "PT";
            DateTime today = DateTime.Today;
            String nowDate = today.ToString("yyyyMMdd");
            string sql_1 = "select top 1 MaPTKB from PhieuThuKhamBenh where MaPTKB like @maphieu + '%' order by MaPTKB desc";
            object[] param_1 = { "@maphieu", prefixKey + nowDate };

            string maPT = utils.genKey(sql_1, param_1, 2, "PT");
            return maPT;
        }

        public int insertPhieuThu(string maPT, string lyDoThu)
        {
            DateTime today = DateTime.Today;
            string sql_2 = "insert into PhieuThuKhamBenh values (@mapt, @ngaylap, @lydo)";
            object[] param_2 = { "@mapt", maPT, "@ngaylap", today, "@lydo", lyDoThu };

            int result = connectDB.ExeNonQuery(sql_2, param_2);
            return result;
        }

    }
}
